package com.hxit.huaxiamelongarden.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hxit.huaxiamelongarden.domin.dto.CommentDto;
import com.hxit.huaxiamelongarden.domin.po.Comment;
import com.hxit.huaxiamelongarden.mapper.CommentMapper;
import com.hxit.huaxiamelongarden.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName CommentServiceImpl
 * @description 评论逻辑实现类
 * @Author 12694
 * @Date 2025/1/30 14:41
 * @Version 1.0
 **/
@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentMapper commentMapper;
    //查询帖子评论
    @Override
    public List<Comment> getByContentId(int contentId) {
        LambdaQueryWrapper<Comment> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Comment::getContentId,contentId);
        return commentMapper.selectList(queryWrapper);
    }

    //添加评论
    @Override
    public void addComment(CommentDto commentDto) {
        Comment comment = BeanUtil.copyProperties(commentDto, Comment.class);
        commentMapper.insert(comment);
    }
}
